<template>
  <view class="login-container">
    <view class="login-title">欢迎登录</view>
    <view class="login-desc" @tap="handleCopy">code: {{authCode}} 复制</view>
    <view class="login-btns">
      <u-button :customStyle="btnCustomStyle" @click="handleClick"> 一键登录 </u-button>
    </view>
  </view>
</template>

<script>
import { login } from "@/apis/user"
import { setToken, setUserInfo } from "@/utils/auth.js"
export default {
  data() {
    return {
      checked: [],
      btnCustomStyle: {
        height: "88rpx",
        borderRadius: "20rpx",
        background: "#fff",
        color: "#21897D",
        border: "none",
        fontSize: "34rpx",
      },
      codeBtnCustomStyle: {
        height: "100rpx",
        lineHeight: "100rpx",
        textAlign: "center",
        borderRadius: "20rpx",
        background: "rgba(255, 255, 255, 0.4)",
        border: "none",
        fontSize: "34rpx",
      },
      authCode: ''
    }
  },
  methods: {
    handleClick() {
      console.log('1 :>> ', 1);
      dd.getAuthCode({
        corpId: "dingdc2ddfa8e636d3c435c2f4657eb6378f",
        success: (res) => {
          const { authCode } = res
          this.authCode = authCode
          console.log("authCode :>> ", authCode)
          const data = {
            dingCode: authCode,
          }
          login(data).then((res) => {
            const userInfo = {
              username: res.username,
            }
            setUserInfo(userInfo)
            setToken(res.accessToken)
            dd.reLaunch({
              url: "/pages/index/index",
            })
          })
        },
        fail: (err) => {
          console.log("err :>> ", err)
        },
        complete: () => {},
      })
    },
    handleCopy() {
      dd.setClipboard({
        text: this.authCode,
        success: () => {
          dd.showToast({
            content: "复制成功",
          })
        },
      })
    },
  },
}
</script>

<style lang="less" scoped>
.login-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #fff;
  // padding-top: 180rpx;
  background-image: url(../../static/images/login-bg.png);
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
.login-title {
  font-size: 72rpx;
  font-weight: bold;
  color: #fff;
  margin-top: 200rpx;
  margin-bottom: 20rpx;
  font-family: Alimama ShuHeiTi;
}
.login-desc {
  font-size: 30rpx;
  color: #ffffff;
}
.login-btns {
  width: 80vw;
  display: flex;
  flex-direction: column;
  gap: 32rpx;
  margin-top: 40rpx;
}

.login-protocol {
  display: flex;
  align-items: center;
  font-size: 24rpx;
  color: #fff;
  margin-top: 40rpx;
}
.protocol-text {
  margin: 0;
}
.protocol-link {
  color: #fff6bf;
  margin: 0rpx;
}
</style>
